package com.ruoyi.common.utils;

import cn.hutool.core.thread.ThreadFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 说明：HTTP接口发送线程池
 * @author qiqi
 * @version 2019年02月27日 下午2:31:42
 */

public class HttpApiThreadPool {
	  private HttpApiThreadPool() {
		    throw new IllegalStateException("Utility class");
		  }
	  private static final Logger LOG = LoggerFactory.getLogger(HttpApiThreadPool.class);
	/** 获取当前系统的CPU 数目*/
	static int cpuNums = Runtime.getRuntime().availableProcessors();
	/** 线程池核心池的大小*/
	private static int corePoolSize = 30;
	/** 线程池的最大线程数*/
	private static int maximumPoolSize = 80;
	@SuppressWarnings("all")
	public static ExecutorService threadPool = null;
	
	
	/**
	 * 静态方法
	 */
	static{
		LOG.info("创建线程数:{},最大线程数:{}",corePoolSize,maximumPoolSize);
		//建立10个核心线程，线程请求个数超过20，则进入队列等待
		threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 0L,
				TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(40000), new ThreadFactoryBuilder().setNamePrefix("SCRM-%d").build());
	}

}
